package com.fuxi.cloud.desreport.service.a;

import com.fuxi.cloud.desreport.dao.JimuReportDataSourceDao;
import com.fuxi.cloud.desreport.entity.JmReportDataSource;
import com.fuxi.cloud.desreport.service.IJmReportDbSourceService;
import com.fuxi.cloud.dyndb.vo.JmreportDynamicDataSourceVo;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.minidao.util.SnowflakeIdWorker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * a
 *
 * @Author: 扫地僧
 * @CreateTime: 2021-05-03
 */
@Service("jmReportDbSourceServiceImpl")
public class i implements IJmReportDbSourceService {
    private static final Logger a = LoggerFactory.getLogger(i.class);
    @Autowired
    private JimuReportDataSourceDao dataSourceDao;

    public i() {
    }

    @Override
    public JmReportDataSource selectById(String id) {
        return this.dataSourceDao.get(id);
    }

    @Override
    public Integer excelQueryCode(String dbKey) {
        return this.dataSourceDao.excelQueryId(dbKey);
    }

    @Override
    public List<JmReportDataSource> querySourceList(String createBy) {
        return this.dataSourceDao.selectListByUser(createBy);
    }

    @Override
    public JmreportDynamicDataSourceVo getByDbKey(String dbKey) {
        JmReportDataSource jmReportDataSource = this.dataSourceDao.get(dbKey);
        return new JmreportDynamicDataSourceVo(jmReportDataSource);
    }

    @Override
    public JmReportDataSource getById(String dbSourceId) {
        return this.dataSourceDao.get(dbSourceId);
    }

    @Override
    public void saveOrUpdate(JmReportDataSource sysDataSource) {
        if (StringUtils.isNotEmpty(sysDataSource.getId())) {
            this.dataSourceDao.update(sysDataSource);
        } else {
            sysDataSource.setId(String.valueOf(SnowflakeIdWorker.generateId()));
            this.dataSourceDao.insert(sysDataSource);
        }

    }

    @Override
    public void removeById(String id) {
        this.dataSourceDao.deleteById(id);
    }
}

